package com.jason.bookworm.controller;

import com.jason.bookworm.dao.pojo.Comment;
import com.jason.bookworm.response.Result;
import com.jason.bookworm.service.HandleCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private HandleCommentService handleCommentService;

    //获取该书所有评论
    @GetMapping("/{bookID}")
    public Result<List<Comment>> getAllComment(@PathVariable Integer bookID) {
        return handleCommentService.getAllComment(bookID);
    }

    //发表评论
    @PostMapping
    @Secured("reader")
    public Result<Object> addOneComment(@RequestBody Comment comment) {
        return handleCommentService.addOneComment(comment);
    }

    //删除评论
    @DeleteMapping("/{commentID}")
    @Secured("reader")
    public Result<Object> deleteOneComment(@PathVariable Integer commentID) {
        return handleCommentService.deleteOneComment(commentID);
    }
}
